package cn.zh.npro.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import cn.zh.npro.Adapter.OgAdapter;
import cn.zh.npro.Item.OdItem;
import cn.zh.npro.R;

public class OrGoods extends BaseActivity {
   ImageView mc_back;
    String ga;

    ArrayList<OdItem> odItems=new ArrayList<OdItem>();
    ListView odlist;
    OgAdapter ogAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_or_goods);
        ga = getIntent().getStringExtra("ja");
        initgd();
        getdata();
        }

    public void initgd(){
        mc_back=findViewById(R.id.mc_back);
        odlist=findViewById(R.id.odlist);
        ogAdapter=new OgAdapter(OrGoods.this,odItems);
        odlist.setAdapter(ogAdapter);
        mc_back.setOnClickListener(this);
        }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        int id=view.getId();
        switch (id){
            case R.id.mc_back:
                finish();
                break;
           }
       }

    public void getdata(){
        odItems.clear();
        try {
            JSONArray ja=new JSONArray(ga);
             for (int i=0;i<ja.length();i++){
                 JSONObject ji=ja.getJSONObject(i);
                 String SellCount =ji.getString("SellCount");
                 String SellPrice =ji.getString("SellPrice");
                 String Unit2=ji.getString("Unit2");
                 String GoodsID =ji.getString("GoodsID");
                 String GoodsName =ji.getString("GoodsName");
                 String IndexURL =ji.getString("IndexURL");
                 String Price_Detail =ji.getString("Price_Detail");
                 String GoodsNo =ji.getString("GoodsNo");
                 String SpecName =ji.getString("SpecName");
                 String SpecID =ji.getString("SpecID");
                 OdItem odItem=new OdItem(SellCount,SellPrice,Unit2,GoodsID,GoodsName,IndexURL,Price_Detail,
                         GoodsNo,SpecName,SpecID);
                 odItems.add(odItem);
                }
            ogAdapter.notifyDataSetChanged();

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }


  }
